<?php
/**
 * Created by PhpStorm.
 * Author: 赵凯
 * Date: 2019/12/10
 * Time: 16:44
 */

namespace gzapi\common\model;


use think\Db;
use think\Model;

class RlHiseServiceProjectModel extends Model
{
    protected $pk = 'hise_service_project_id';
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';

    public static function  getHiseList($where,$field){
        $prefix = 'cmf_';
        $join = [
            ["{$prefix}rl_et_azd azd", 'hise.azd = azd.engineer_code'],
        ];
        $list = self::alias('hise')
            ->join($join)
            ->where($where)
            ->order('hise.hise_service_project_id desc')
            ->field($field)
            ->select()
            ->toArray();
        foreach ($list as $k =>$v){
            if($list[$k]['yyaz_sj']){
                $list[$k]['yyaz_sj'] = date('Y-m-d',$list[$k]['yyaz_sj']);
            }else{
                $list[$k]['yyaz_sj'] = '';
            }
            if(empty($v['qx'])){
                $city = Db::name('rl_hise_dq_table')->where('dq_code',$v['qx'])->field('dq_name')->find()['dq_name'];
                $provice = Db::name('rl_hise_area')->where('sf_code',$v['qx'])->field('sf_name')->find()['sf_name'];
                $list[$k]['address'] = $provice.$city.$list[$k]['address'];
            }else{
                $xq = Db::name('rl_hise_qx_table')->where('qx_code',$v['qx'])->field('qx_name')->find()['qx_name'];
                $city = Db::name('rl_hise_dq_table')->where('dq_code',$v['city'])->field('dq_name')->find()['dq_name'];
                $provice = Db::name('rl_hise_area')->where('sf_code',$v['provice'])->field('sf_name')->find()['sf_name'];
                $list[$k]['address'] = $provice.$city.$xq.$list[$k]['address'];
            }
        }

        return $list;
    }
}